var ns, toast, UIActionProgress, UISearchBar;
var app = new Vue({
    el: '#app',
    data: {
        IsMain:1,
        list: [],
        TypeID:0,
        IsShow:false,
        form: {
            pageindex: 0,
            pagesize: 2,
        },
        showsearch:false,
        showTop:false,
        name:'',
        typeurl:'',
        moduleList:[],
        touchID:0,
        SortOrder:0,

    },
    methods: {
        get_data: function () {
            var that = this;
            var options = {};
            options.action = "getsysmenulist";
            options.IsMain=that.IsMain;
            toast.loading({
                title: "加载中",
                duration: 2000
            }, function (ret) { });
            ns.post(options, function (succeed, data, err) {
                toast.hide();
                if (succeed) {
                    if (data.postionName) that.postionName = data.postionName; 
                    if(data.list.length>0){
                        that.list=data.list;
                    }
                    for(var i=0;i<data.list.length;i++){
                        if(data.list[i].AddTime){
                            data.list[i].AddTime = ns.SetTime_style(data.list[i].AddTime);
                        }else{
                            data.list[i].AddTime='';
                        }
                        
                    }
                    
                } 
            });
        },
        //点击遮罩关闭弹窗
        doHideSearch:function(){
            var that=this;
            that.showsearch = false;
            that.showTop=false;
            that.IsMain=1;
            that.get_data();
        },
        //长按弹出操作框
        gettouchStart:function(index,id,name,IsShow,SortOrder){
            var that = this;
            api.addEventListener({
                name:'longpress'
            }, function(ret){               
                that.showTop=!that.showTop;  
                that.name=name;
                that.touchID=id;
                that.IsShow=IsShow;
                that.SortOrder=SortOrder;
            })
        },
        //置顶
        Totoplist:function(){
            var that=this;
            that.moduleList=[];
            that.moduleList.push({
                ID:that.touchID,
                SortOrder:1,
                IsShow:that.IsShow,
            });
            var options = {};
            options.action = "savemodulesuctom";
            options.moduleList = JSON.stringify(that.moduleList);
            options.IsSortOrder=1;
            ns.post(options, function(succeed, data, err) {
                that.showTop=false;
                if (data.status==true) {
                    
                    that.get_data();
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });

        },
        //删除
        deletelist:function(){
            var that=this;
            var isshow=!that.IsShow;
            that.moduleList=[];
            that.moduleList.push({
                ID:that.touchID,
                SortOrder:that.SortOrder,
                IsShow:isshow,
            });
            var options = {};
            options.action = "savemodulesuctom";
            options.moduleList = JSON.stringify(that.moduleList);
            options.IsSortOrder=0;
            ns.post(options, function(succeed, data, err) {
                that.showTop=false;
                if (data.status==true) {
                    api.toast({
                        msg:'删除成功',
                        duration: 2000,
                        location: 'bottom'
                    });
                    that.get_data();
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });
        },
        do_opentypelist:function(ID){
            var title;
            if(ID==814){
                title="客服工单";
                ns.openWin('msgcustomerserviceList',title,{
                    IsWorkOrder:1,
                    servicetype:1
                });
                return;
            }
            if(ID==695){
                title="投诉建议";
                ns.openWin('msgcustomerserviceList',title,{
                    IsWorkOrder:2,
                    servicetype:2
                });
                return;
            }
            if(ID==690){
                title="设备巡检";
                ns.openWin('equipment_typelist',title);
                return;
            }
            if(ID==692){
                title="安防巡更";
                ns.openWin('patrolplan_typelist',title);
                return;
            }
            if(ID==693){
                title="保洁绿化";
                ns.openWin('bjlh_typelist',title);
                return;
            }
            if(ID==963){
                title="通知公告";
                ns.openWin('tongzhigonggao_typelist',title);
                return;
            }
            if(ID==956){
                title="审批中心";
                ns.openWin('examine_typelist',title);
                return;
            }
            if(ID==1064){
                title="内部通知";
                ns.openWin('neibutz_typelist',title);
                return;
            }
        },
    }
});
apiready = function () {
    api.parseTapmode();
    ns = window.Foresight.Util;
    UIActionProgress = api.require('UIActionProgress');
    toast = new auiToast();
    app.get_data();

    ns.init_pull(true);
    api.addEventListener({
        name: 'isreadtrue'
    }, function (ret, err) {
        if (ret) {
            setTimeout(function () {
                app.get_data();
            }, 500);
        } else {
            api.toast({
                msg: err,
                duration: 2000,
                location: 'bottom'
            });
        }
    });
    api.addEventListener({
        name: 'isreadCustomer'
    }, function () {
        app.get_data();
    });
    api.addEventListener({
        name: 'isreadEquipment'
    }, function () {
        app.get_data();
    });
    api.addEventListener({
        name: 'isreadPatrol'
    }, function () {
        app.get_data();
    });
    api.addEventListener({
        name: 'isreadBjlh'
    }, function () {
        app.get_data();
    });
    api.addEventListener({
        name: 'isreadTongzhi'
    }, function () {
        app.get_data();
    });
    api.addEventListener({
        name: 'isreadExamine'
    }, function () {
        app.get_data();
    });
    api.addEventListener({
        name: 'home_new_updata'
    }, function () {
        app.get_data();
    });
    api.addEventListener({
        name: 'purchase_updata'
    }, function () {
        app.get_data();
    });
}
